#include<iostream>
#include <string>

#include "Log.hpp"
#include "UdpServer.hpp"
#include "Common.hpp"
#include "User.hpp"
#include "Internet.hpp"
using namespace LogModule;
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cerr << "Usage: " << argv[0] << " localport" << std::endl;
        Die(USAGE_ERR);
    }

    ENABLE_CONSOLE_LOG();
   //std::string ip = argv[1];
    uint16_t port = std::stoi(argv[1]);

    
    std::shared_ptr<Usermanger> umanger = std::make_shared<Usermanger>();
    std::unique_ptr<UDPServer> svr_uptr = std::make_unique<UDPServer>(port);
    svr_uptr->Register([&umanger](InetAddr inetaddr){
        umanger->AddUSer(inetaddr);
    },
    [&umanger](int sockfd,const std::string& message){
        umanger->Router(sockfd,message);
    });
    svr_uptr->InitServer();
    svr_uptr->Start();

    return 0;
}